﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.RemoteCtrls
{
    /// <summary>
    /// 远程代理基类
    /// </summary>
    public abstract class MarshalByRefProxyBase : MarshalByRefObject, IDisposable
    {
        protected bool _isDisposed;
       
        public override object InitializeLifetimeService()
        {
            return null;
        }

        /// <summary>
        /// 释放
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this._isDisposed)
            {
                if (disposing)
                {
                    this.OnDisposing();
                }
                RemotingServices.Disconnect(this);
                this._isDisposed = true;
            }
        }

        protected virtual void OnDisposing()
        {
        }

        ~MarshalByRefProxyBase()
        {
            this.Dispose(false);
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }   
    }
}
